package com.atguigu.dao.impl;

import com.atguigu.dao.DeployServiceModuleDao;
import com.atguigu.pojo.DeployServiceModule;

import java.util.List;

public class DeployServiceModuleDaoImpl extends BaseDao implements DeployServiceModuleDao {
    @Override
    public int addDeployServiceModule(DeployServiceModule deployServiceModule) {
        System.out.println("DeployServiceModuleDaoImpl 程序在["+Thread.currentThread().getName()+"]线程中");
        String sql="insert into t_deployServiceModule(`id`,`deployGoalId`,`deployEnvId`,`projectId`,`projectModuleId`,`targetNodeId`,`fileUrl`,`status`,`lastId`) values(?,?,?,?,?,?,?,?,?);";
            return update(sql,deployServiceModule.getId(),deployServiceModule.getDeployGoalId(),deployServiceModule.getDeployEnvId(),deployServiceModule.getProjectId(),deployServiceModule.getProjectModuleId(),
                    deployServiceModule.getTargetNodeId(),deployServiceModule.getFileUrl(),deployServiceModule.getStatus(),deployServiceModule.getLastId());
    }

    @Override
    public int deleteDeployServiceModuleById(String id) {
        String sql="delete from t_deployServiceModule where id=?";
        return update(sql,id);
    }

    @Override
    public int updateDeployServiceModule(DeployServiceModule deployServiceModule) {
        //System.out.println(deployServiceModule);
        String sql="update t_deployServiceModule set `id`=?,`deployGoalId`=?,`deployEnvId`=?,`projectId`=?,`projectModuleId`=?,`targetNodeId`=?,`fileUrl`=?,`status`=?,`lastId`=? where id=?";
        return update(sql,deployServiceModule.getId(),deployServiceModule.getDeployGoalId(),deployServiceModule.getDeployEnvId(),deployServiceModule.getProjectId(),deployServiceModule.getProjectModuleId(),
                deployServiceModule.getTargetNodeId(),deployServiceModule.getFileUrl(),deployServiceModule.getStatus(),deployServiceModule.getLastId(),
                deployServiceModule.getId());
    }

    @Override
    public DeployServiceModule queryDeployServiceModuleById(String id) {
        String sql ="select `id`,`deployGoalId`,`deployEnvId`,`projectId`,`projectModuleId`,`targetNodeId`,`fileUrl`,`status`,`lastId` from t_deployServiceModule where id=?";
        return queryForOne(DeployServiceModule.class,sql,id);
    }
    @Override
    public DeployServiceModule queryDeployServiceModuleByLastId(String lastId) {
        String sql ="select `id`,`deployGoalId`,`deployEnvId`,`projectId`,`projectModuleId`,`targetNodeId`,`fileUrl`,`status`,`lastId` from t_deployServiceModule where lastId=?";
        return queryForOne(DeployServiceModule.class,sql,lastId);
    }

    @Override
    public List<DeployServiceModule> queryDeployServiceModules() {
        String sql ="select `id`,`deployGoalId`,`deployEnvId`,`projectId`,`projectModuleId`,`targetNodeId`,`fileUrl`,`status`,`lastId`  from t_deployServiceModule";
        return queryForList(DeployServiceModule.class,sql);
    }
    @Override
    public List<DeployServiceModule> queryDeployServiceModulesByDeployGoalId(String deployGoalId){
        String sql ="select `id`,`deployGoalId`,`deployEnvId`,`projectId`,`projectModuleId`,`targetNodeId`,`fileUrl`,`status`,`lastId`  from t_deployServiceModule where deployGoalId=?";
        return queryForList(DeployServiceModule.class,sql,deployGoalId);
    }
    @Override
    public Integer queryForPageTotalCount() {
        String sql="select count(*) from t_deployServiceModule";
        Number serverCount=(Number) queryForSingleValue(sql);//这个语句似乎可以返回任何类型的查询
        //System.out.println(bookCount);
        return serverCount.intValue();
    }

    @Override
    public List<DeployServiceModule> queryForPageItems(Integer begin, Integer pageSize) {
        String sql ="select `id`,`deployGoalId`,`deployEnvId`,`projectId`,`projectModuleId`,`targetNodeId`,`fileUrl`,`status`,`lastId`  from t_deployServiceModule limit ?,?";
        return queryForList(DeployServiceModule.class,sql,begin,pageSize);

    }
}
